const express = require('express');
const app = express();
const cors = require('cors');
const expressJWT = require('express-jwt')
app.listen(3307,()=>console.log('大事件接口开启'));
app.use(cors());
app.use(express.urlencoded({extended:false}))

// 解析token字符串,控制那些接口必须比对token才能访问
app.use(expressJWT({secret:'bigevent'}).unless({path:/^\/api$/})) //除了api开头的接口,其他的必须比对token


// 加载路由模块

app.use('/api',require('./routers/login.js'));
app.use('/my/article',require('./routers/article.js'));
app.use('/my',require('./routers/user.js'));
app.use('/my/article',require('./routers/category.js'));

// 错误处理中间件
app.use(function(err,req,res,next){
    if(err.name === 'UnauthorizedError'){
        res.status(401).send({status:402,message:'身份认证失败!'});
    }

})






